package com.markerhub.controller;


import com.markerhub.Shiro.AccountProfile;
import com.markerhub.Util.ShiroUtil;
import com.markerhub.common.lang.Result;
import com.markerhub.entity.User;
import com.markerhub.service.UserService;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2022-03-23
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequiresAuthentication
    @GetMapping("/index")
    public Object index(){
        User user =userService.getById(1L);
        return Result.succ(200,"操作成功",user);
    }

    @PostMapping("/register")
    public Result register(@Validated @RequestBody User user){
        return Result.succ(userService.register(user));
    }

    //测试获得登录信息
    @GetMapping("/Tests")
    public String Tests(){
        //登录信息
        AccountProfile accountProfile =ShiroUtil.getProfile();
        System.out.println("账号："+accountProfile.getUsername());
        return "完成";
    }


    @CrossOrigin
    @RequestMapping("/oss/policy")
    public Result policy(){
        return Result.succ(userService.policy());
    }

}
